﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pavilion
{
    public class DrawItem
    {
        private double drawOrder;

        public bool IsVisible { get; set; }
        public Action DrawAction { get; set; }
        public event Action<DrawItem> DrawOrderChanged, Disposed;

        public DrawItem(double drawOrder, Action drawAction)
        {
            this.drawOrder = drawOrder;
            this.DrawAction = drawAction;
            this.IsVisible = true;
        }

        public void Dispose()
        {
            DrawAction = null;

            OnDisposed();
        }

        public double DrawOrder
        {
            get { return drawOrder; }
            set
            {
                if (drawOrder == value)
                    return;

                drawOrder = value;
                OnDrawOrderChanged();
            }
        }

        private void OnDrawOrderChanged()
        {
            if (DrawOrderChanged != null)
                DrawOrderChanged(this);
        }

        private void OnDisposed()
        {
            if (Disposed != null)
                Disposed(this);
        }
    }
}
